<?php

namespace App\Http\Controllers\Console;

use App\Http\Controllers\Controller;
use App\Model\ShopRegisterModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;


//车主认证相关
class CarownerController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     * 车主信息提交
     */
    public function chezhu(Request $request)
    {
        //
        $token = $request->header('Authorization');
        $redis = app("redis.connection");
        $val = $redis->get($token);
        if(!$val){
            return json_encode(['code'=>100,'msg'=>'token已过期，请从新登陆','data'=>[]]);
        }
        $val = json_decode($val,true);
        $val = json_decode($val,true);
        $shop_id=$val['uid'];

        $data = [
            'shop_id'=> $shop_id,
            'area_id' => $request->area_id,
            'address' => $request->address,
            'user_name' => $request->user_name,
            'id_card' => $request->id_card,
            'mobile' => $request->mobile,
            'second_mobile' => $request->second_mobile,
            'card_front' => $request->card_front,
            'card_back' => $request->card_back,
            //驾驶证正反面
            'driver_front' => $request->card_front,
            'driver_back' => $request->card_back,

            //车主的type数值可以为2
            'type' => 2,
            //新注册标识未审核
            'status' => 1,
        ];
        $ShopRegisterModel = new ShopRegisterModel();

        $re = $ShopRegisterModel->create($data);
        if(!$re){
            return ['msg'=>'对不起，车主信息提交失败','code'=>100];
        }
        return ['msg'=>'恭喜，车主信息提交成功','code'=>200];
    }

    /**
     * @param Request $request
     * @return array
     * 车辆信息提交
     */
    public function cheliang(Request $request){
        //

        $token = $request->header('Authorization');
        $redis = app("redis.connection");
        $val = $redis->get($token);
        if(!$val){
            return json_encode(['code'=>100,'msg'=>'token已过期，请从新登陆','data'=>[]]);
        }
        $val = json_decode($val,true);
        $val = json_decode($val,true);
        $shop_id=$val['uid'];
        //{"data":["http:\/\/cdn.juchuyuncang.com\/2020\/08\/24\/lJjgMN1nKaQRlveP6GQAfCPLGTk25P7nJNWYicZg.png","http:\/\/cdn.juchuyuncang.com\/2020\/08\/24\/03vwgDSjWZJgxWPRpbznnBWqjBI40OeetIdRoRdN.png"]}

        $data = [
            //车辆图片这里接收一个json,格式类似
            //{"data":["http:\/\/cdn.juchuyuncang.com\/2020\/08\/24\/lJjgMN1nKaQRlveP6GQAfCPLGTk25P7nJNWYicZg.png","http:\/\/cdn.juchuyuncang.com\/2020\/08\/24\/03vwgDSjWZJgxWPRpbznnBWqjBI40OeetIdRoRdN.png"]}
            'car_photo' => $request->car_photo,
            'drive_llicense_front' => $request->drive_llicense_front,
            'drive_llicense_back' => $request->drive_llicense_back,
            'car_type' => $request->car_type,
            'car_number' => $request->car_number,
            'car_leixing' => $request->car_leixing,
            'car_length' => $request->car_length,
            'car_load' => $request->car_load,
        ];
        $ShopRegisterModel = new ShopRegisterModel();

        $re = $ShopRegisterModel->where('shop_id',$shop_id)->update($data);
        if(!$re){
            return ['msg'=>'对不起，车辆信息提交失败','code'=>100];
        }
        return ['msg'=>'车主和车辆信息全部提交成功，请耐心等待审核','code'=>200];
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
